package com.project.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.project.service.DataManage;
import com.project.DAO.*;
import com.project.mapper.*;
import com.project.entity.*;

public class DataManageService implements DataManage {
	private ProjectManagementMapper projectManagementMapper;
	private ProjectManagementExample projectmanagementExample;

	public ProjectManagementMapper getProjectManagementMapper() {
		return projectManagementMapper;
	}

	public void setProjectManagementMapper(
			ProjectManagementMapper projectManagementMapper) {
		this.projectManagementMapper = projectManagementMapper;
	}

	public ProjectManagementExample getProjectmanagementExample() {
		return projectmanagementExample;
	}

	public void setProjectmanagementExample(
			ProjectManagementExample projectmanagementExample) {
		this.projectmanagementExample = projectmanagementExample;
	}

	public int countAllProject() {
		ProjectManagementExample example = new ProjectManagementExample();
		return this.projectManagementMapper.countByExample(example);		
	}

	/**
	 * 获取所有的项目
	 */
	public List<ProjectManagement> getAllProject(Integer start, Integer end){
		System.out.println(start);
		System.out.println(end);
		return projectManagementMapper.getAllProject(start , end);
	}

	/**
	 * 插入项目记录
	 */
	public void insertProject(ProjectManagement projectManagement) {
		this.projectManagementMapper.insert(projectManagement);
	}

	/**
	 * 动态条件查询
	 */
	public List<ProjectManagement> multiConditionQuery(String type,
			String keyWord, String beginYear, String endYear) {
		ProjectManagementExample example = new ProjectManagementExample();
		System.out.print(keyWord);
		if (!type.equals("") && type != null && !keyWord.equals("")
				&& keyWord != null)// 判断若查询条件且关键字都不为空，则嵌入该查询条件
		{
			if (type.equals("projectid")) {
				example.createCriteria().andProjectidEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("projectnumber")) {
				example.createCriteria().andProjectnumberEqualTo(keyWord);
			}

			if (type.equals("projectname")) {
				example.createCriteria().andProjectnameEqualTo(keyWord);
			}

			if (type.equals("location")) {
				example.createCriteria().andLocationEqualTo(keyWord);
			}

			if (type.equals("mainundertakeunit")) {
				example.createCriteria().andMainundertakeunitEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("guaranteeunit")) {
				example.createCriteria().andGuaranteeunitEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("unitedunitone")) {
				example.createCriteria().andUnitedunitoneEqualTo(keyWord);
			}

			if (type.equals("unitedunitone")) {
				example.createCriteria().andUnitedunitoneEqualTo(keyWord);
			}

			if (type.equals("unitedunittwo")) {
				example.createCriteria().andUnitedunittwoEqualTo(keyWord);
			}

			if (type.equals("unitedunitthree")) {
				example.createCriteria().andUnitedunitthreeEqualTo(keyWord);
			}

			if (type.equals("unitedunitfour")) {
				example.createCriteria().andUnitedunitfourEqualTo(keyWord);
			}

			if (type.equals("establishprojectyear")) {
				example.createCriteria()
						.andEstablishprojectyearEqualTo(keyWord);
			}

			if (type.equals("mainmanagingdepartment")) {
				example.createCriteria().andMainmanagingdepartmentEqualTo(
						keyWord);
			}

			if (type.equals("followupperson")) {
				example.createCriteria().andFollowuppersonEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("projectplancatagory")) {
				example.createCriteria().andProjectplancatagoryEqualTo(keyWord);
			}

			if (type.equals("field")) {
				example.createCriteria().andFieldEqualTo(keyWord);
			}

			if (type.equals("subfield")) {
				example.createCriteria().andSubfieldEqualTo(keyWord);
			}

			if (type.equals("issuefilenumber")) {
				example.createCriteria().andIssuefilenumberEqualTo(keyWord);
			}

			if (type.equals("winbidmoney")) {
				example.createCriteria().andWinbidmoneyEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("projectdirector")) {
				example.createCriteria().andProjectdirectorEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("officephone")) {
				example.createCriteria().andOfficephoneEqualTo(keyWord);
			}

			if (type.equals("mobilephone")) {
				example.createCriteria().andMobilephoneEqualTo(keyWord);
			}

			if (type.equals("directoremail")) {
				example.createCriteria().andDirectoremailEqualTo(keyWord);
			}

			if (type.equals("contactman")) {
				example.createCriteria().andContactmanemailEqualTo(keyWord);
			}

			if (type.equals("phoneone")) {
				example.createCriteria().andPhoneoneEqualTo(keyWord);
			}

			if (type.equals("phonetwo")) {
				example.createCriteria().andPhonetwoEqualTo(keyWord);
			}

			if (type.equals("contactmanemail")) {
				example.createCriteria().andContactmanemailEqualTo(keyWord);
			}

			/*
			 * if(type.equals("checkdate")){
			 * example.createCriteria().andCheckdateEqualTo(null); }
			 */

			if (type.equals("projectschedule")) {
				example.createCriteria().andProjectscheduleEqualTo(keyWord);
			}

			if (type.equals("projectchange")) {
				example.createCriteria().andProjectchangeEqualTo(keyWord);
			}

			if (type.equals("inventpatentapplication")) {
				example.createCriteria().andInventpatentapplicationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("inventpatentauthorization")) {
				example.createCriteria().andInventpatentauthorizationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("usenewapplication")) {
				example.createCriteria().andUsenewapplicationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("usenewauthorization")) {
				example.createCriteria().andUsenewauthorizationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("appearancedesignapplication")) {
				example.createCriteria().andAppearancedesignapplicationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("appearancedesignauthorization")) {
				example.createCriteria()
						.andAppearancedesignauthorizationEqualTo(
								Integer.valueOf(keyWord));
			}

			if (type.equals("foreignpatent")) {
				example.createCriteria().andForeignpatentEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newtechnology")) {
				example.createCriteria().andNewtechnologyEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newproduct")) {
				example.createCriteria().andNewproductEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newmaterial")) {
				example.createCriteria().andNewmaterialEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newequipment")) {
				example.createCriteria().andNewequipmentEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("computersoftware")) {
				example.createCriteria().andComputersoftwareEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("paper")) {
				example.createCriteria().andPaperEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("technologystandard")) {
				example.createCriteria().andTechnologystandardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("nationalaward")) {
				example.createCriteria().andNationalawardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("provincialaward")) {
				example.createCriteria().andProvincialawardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("cityaward")) {
				example.createCriteria().andCityawardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("doctor")) {
				example.createCriteria().andDoctorEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("master")) {
				example.createCriteria().andMasterEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("undergraduate")) {
				example.createCriteria().andUndergraduateEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("fundsavailable")) {
				example.createCriteria().andFundsavailableEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("fundsinvestment")) {
				example.createCriteria().andFundsinvestmentEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("benefitacquired")) {
				example.createCriteria().andBenefitacquiredEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("projectsummary")) {
				example.createCriteria().andProjectsummaryEqualTo(keyWord);
			}
		}

		List<ProjectManagement> rs = new ArrayList();
		List<ProjectManagement> tmp = this.projectManagementMapper
				.selectByExample(example);
		if (beginYear != null && (!beginYear.equals(""))) {
			if (endYear != null && (!endYear.equals(""))) {
				for (ProjectManagement pro : tmp) {
					if (Integer.parseInt(pro.getEstablishprojectyear()
							.toString()) <= Integer.parseInt(endYear)
							&& Integer.parseInt(pro.getEstablishprojectyear()
									.toString()) >= Integer.parseInt(beginYear)) {
						rs.add(pro);
					}
				}// 以立项时间为查询条件之一
			} else {
				for (ProjectManagement pro : tmp) {
					if (Integer.parseInt(pro.getEstablishprojectyear()
							.toString()) >= Integer.parseInt(beginYear)) {
						rs.add(pro);
					}
				}
			}
		} else if (endYear != null && (!endYear.equals(""))) {
			for (ProjectManagement pro : tmp) {
				if (Integer.parseInt(pro.getEstablishprojectyear().toString()) <= Integer
						.parseInt(endYear)) {
					rs.add(pro);
				}

			}
		}
		return tmp;
	}

}
